package com.fau.fm.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 休假已通过表
 * @author dangjh
 * @datetime 2014年10月25日,下午2:11:11
 */
@Entity
@Table(name = "medical_leave_approve")
public class MedicalLeaveApprove implements Serializable, JSONAware {

	private static final long serialVersionUID = -4203911331040536278L;

	private String id;
	private MedicalAdmin user;				//休假人id
	private String description;				//休假原因描述
	private Date startTime;					//休假开始时间
	private Date endTime;					//休假结束时间
	private Integer days;					//休假天数
	private String eid;						//企业id
	private String leaveType;				//休假类型
	private Date createTime = new Date();	//创建时间
	
	private String name;
	private String infoId;
	private String leaveTypeName;
	
	public MedicalLeaveApprove(){
	}

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id")
	public MedicalAdmin getUser() {
		return user;
	}

	public void setUser(MedicalAdmin user) {
		this.user = user;
	}

	@Column(name = "description", length = 255)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "start_time")
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@Column(name = "end_time")
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@Column(name = "days", length = 10)
	public Integer getDays() {
		return days;
	}

	public void setDays(Integer days) {
		this.days = days;
	}
	
	@Column(name = "leave_type", length = 20)
	public String getLeaveType() {
		return leaveType;
	}

	public void setLeaveType(String leaveType) {
		this.leaveType = leaveType;
	}
	
	@Column(name = "eid", length = 32)
	public String getEid() {
		return eid;
	}

	public void setEid(String eid) {
		this.eid = eid;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Transient
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Transient
	public String getInfoId() {
		return infoId;
	}

	public void setInfoId(String infoId) {
		this.infoId = infoId;
	}

	@Transient
	public String getLeaveTypeName() {
		return leaveTypeName;
	}

	public void setLeaveTypeName(String leaveTypeName) {
		this.leaveTypeName = leaveTypeName;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("name", user.getName());
		obj.put("startTime", DateFormatUtils.format(startTime,"yyyy-MM-dd"));
		obj.put("endTime", DateFormatUtils.format(endTime,"yyyy-MM-dd"));
		obj.put("days", days);
		obj.put("leaveType", leaveType);
		obj.put("leaveTypeName", leaveTypeName);
		obj.put("description", description);
		return obj.toJSONString();
	}

}
